//
//  ElarcScalableTableViewCell.swift
//  elarc01
//
//  Created by elarc on 16/5/10.
//  Copyright © 2016年 elarc. All rights reserved.
//

import Foundation

class ElarcScalableTableViewCell: UITableViewCell,ElarcTableViewCellTransform {
    let miniumScale:CGFloat = 0.3
    let interVal:CGFloat = 15
    
    lazy var urlImageView: UIImageView = {
        let h = ScreenWidth*73/160
        let imageView = UIImageView(frame: CGRectMake(0,15, ScreenWidth, h))
        imageView.image = UIImage(named:"panda02")
        return imageView
    }()
    
    lazy var titleLabel: UILabel = {
        let x:CGFloat = 20
        let y:CGFloat = CGRectGetMaxY(self.urlImageView.frame)+15
        let w:CGFloat = ScreenWidth-40
        let h:CGFloat = 15
        let label = UILabel(frame: CGRectMake(x,y,w,h))
        label.textColor = UIColor.blackColor()
        label.font = UIFont.systemFontOfSize(15)
        return label
    }()
    
    lazy var subtitleLabel: UILabel = {
        let x:CGFloat = 20
        let y:CGFloat = CGRectGetMaxY(self.titleLabel.frame)+10
        let w:CGFloat = CGRectGetWidth(self.urlImageView.frame)-100
        let h:CGFloat = 15
        let label = UILabel(frame: CGRectMake(x,y,w,h))
        label.textColor = UIColor.blackColor()
        label.font = UIFont.systemFontOfSize(15)
        return label
    }()
    
    lazy var readCountLabel: UILabel = {
        let x:CGFloat = CGRectGetMaxX(self.subtitleLabel.frame)
        let y:CGFloat = CGRectGetMaxY(self.titleLabel.frame)+10
        let w:CGFloat = ScreenWidth - x - 20
        let h:CGFloat = 15
        let label = UILabel(frame: CGRectMake(x,y,w,h))
        label.textColor = UIColor.blackColor()
        label.font = UIFont.systemFontOfSize(15)
        label.textAlignment = NSTextAlignment.Right
        return label
    }()
    
    lazy var line: UIView = {
        let y:CGFloat = CGRectGetMaxY(self.subtitleLabel.frame)+14
        let linetemp = UIView(frame: CGRectMake(0,y,ScreenWidth,1))
        linetemp.backgroundColor = UIColor.blackColor()
        return linetemp
    }()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = UIColor.whiteColor()
        selectionStyle = UITableViewCellSelectionStyle.None;
        contentView.addSubview(titleLabel)
        contentView.addSubview(subtitleLabel)
        contentView.addSubview(urlImageView)
        contentView.addSubview(line)
        contentView.addSubview(readCountLabel)
    }
    
    override func prepareForReuse() {
        super.prepareForReuse();
        self.urlImageView.transform = CGAffineTransformMakeScale(self.miniumScale, self.miniumScale);
    }
    
    func transformCell(forScale scale: CGFloat) {
        self.urlImageView.transform = CGAffineTransformMakeScale(1.0 - scale, 1.0 - scale);
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}